package com.example.flutter_iot_plugin

import android.content.Context
import android.os.Handler
import android.os.Looper
import androidx.annotation.NonNull
import com.alibaba.ailabs.tg.utils.LogUtils
import com.alibaba.fastjson.JSON
import com.aliyun.alink.business.devicecenter.api.add.*
import com.aliyun.alink.business.devicecenter.api.discovery.*
import com.aliyun.alink.business.devicecenter.base.DCErrorCode
import com.aliyun.iot.aep.sdk.IoTSmart
import com.aliyun.iot.aep.sdk.apiclient.IoTAPIClientFactory
import com.aliyun.iot.aep.sdk.apiclient.callback.IoTCallback
import com.aliyun.iot.aep.sdk.apiclient.callback.IoTResponse
import com.aliyun.iot.aep.sdk.apiclient.request.IoTRequest
import com.aliyun.iot.aep.sdk.apiclient.request.IoTRequestBuilder
import com.aliyun.iot.aep.sdk.framework.AApplication
import com.aliyun.iot.aep.sdk.login.ILoginCallback
import com.aliyun.iot.aep.sdk.login.LoginBusiness
import io.flutter.BuildConfig
import io.flutter.embedding.engine.plugins.FlutterPlugin
import java.util.*
import kotlin.collections.HashMap

// https://github.com/MXCHIP/AlilinkAndroid_Demo/blob/master/app/src/main/java/io/fogcloud/demo/MainActivity.java
/** FlutterIotPlugin */
class FlutterIotPlugin : FlutterPlugin, Pigeon.HostAliLink {

    var flutterApi: Pigeon.FlutterAliLink? = null
    var applicationContext: Context? = null
    val handler by lazy { Handler(Looper.getMainLooper()) }

    @Volatile
    var isInit = false

    override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
        LogUtil.i("onAttachedToEngine,currentThread=${Thread.currentThread()}")
        flutterApi = Pigeon.FlutterAliLink(flutterPluginBinding.binaryMessenger)
        Pigeon.HostAliLink.setup(flutterPluginBinding.binaryMessenger, this)
        applicationContext = flutterPluginBinding.applicationContext


        initIotSmart()

    }


    override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
    }

    private fun initIotSmart() {
        if (isInit) {
            return
        }
        isInit = true
        if (applicationContext is AApplication) {
            LogUtil.i("IoTSmart.init start")
            IoTSmart.init(applicationContext as AApplication) //初始化，App须继承自 AApplication，否则会报错
            LogUtil.i("initIotSmart end")

            IoTSmart.setDebug(BuildConfig.DEBUG)
            LogUtils.enable(true)
        }

    }

    override fun startAddDeviceByBroadcast(productKey: String, productId: String) {
        initIotSmart()

        // 设置设备信息
        val deviceInfo = DeviceInfo()
        deviceInfo.productId = productId
        deviceInfo.productKey = productKey // 商家后台注册的 productKey，不可为空
        deviceInfo.linkType = LinkType.ALI_DEFAULT.getName() // 默认一键配网
        AddDeviceBiz.getInstance().setDevice(deviceInfo)
        LogUtil.i("setDevice:${deviceInfo}")
        // 开始添加设备
        startDevice()
    }

    override fun startAddDeviceBySoftAP(productKey: String, productId: String) {
        initIotSmart()

        // 设置设备信息
        val deviceInfo = DeviceInfo()
        deviceInfo.productId = productId
        deviceInfo.productKey = productKey // 商家后台注册的 productKey，不可为空
        deviceInfo.linkType = LinkType.ALI_SOFT_AP.getName() // 默认一键配网
        AddDeviceBiz.getInstance().setDevice(deviceInfo)
        LogUtil.i("setDevice:${deviceInfo}")
        // 开始添加设备
        startDevice()
    }

    override fun startAddDeviceByBLE(productKey: String, productId: String) {
        initIotSmart()

        // 设置设备信息
        val deviceInfo = DeviceInfo()
        deviceInfo.productId = productId
        deviceInfo.productKey = productKey // 商家后台注册的 productKey，不可为空
        deviceInfo.linkType = LinkType.ALI_BLE.getName() // 默认一键配网
        LogUtil.i("setDevice:${deviceInfo}")
        AddDeviceBiz.getInstance().setDevice(deviceInfo)

        // 开始添加设备
        startDevice()
    }

    override fun stopAddDevice() {
        AddDeviceBiz.getInstance().stopAddDevice()
    }

    override fun startDiscovery() {
        initIotSmart()
        val enumSet = EnumSet.noneOf(DiscoveryType::class.java)
        enumSet.add(DiscoveryType.LOCAL_ONLINE_DEVICE)
        enumSet.add(DiscoveryType.CLOUD_ENROLLEE_DEVICE)
        enumSet.add(DiscoveryType.BLE_ENROLLEE_DEVICE)
        enumSet.add(DiscoveryType.SOFT_AP_DEVICE)
        enumSet.add(DiscoveryType.BEACON_DEVICE)
        LocalDeviceMgr.getInstance().startDiscovery(applicationContext, enumSet, null, object : IDeviceDiscoveryListener {

            override fun onDeviceFound(discoveryType: DiscoveryType, deviceInfos: MutableList<DeviceInfo>) {
                // 发现的设备
                // LOCAL_ONLINE_DEVICE 当前和手机在同一局域网已配网在线的设备
                // CLOUD_ENROLLEE_DEVICE 零配或智能路由器发现的待配设备
                // BLE_ENROLLEE_DEVICE 发现的是蓝牙Wi-Fi双模设备（蓝牙模块广播的subType=2即为双模设备）
                // SOFT_AP_DEVICE 发现的设备热点
                // BEACON_DEVICE 一键配网发现的待配设备
                // APP_FOUND_BLE_MESH_DEVICE 本地蓝牙Mesh发现的待配网设备
                // 注意：发现蓝牙设备需添加 breeze-biz SDK依赖

                /***
                 * discoveryType=BLE_ENROLLEE_DEVICE,size=1
                {
                "id": "null",
                "linkType": "ForceAliLinkTypeNone",
                "productKey": "a1noYnuhf7a",
                "deviceName": "null",
                "productId": "11311349",
                "devType": "ble_subtype_12",
                "remainTime": "null",
                "mac": "84:9D:C2:20:C4:3C",
                "addDeviceFrom": "null",
                "regProductKey": "null",
                "regDeviceName": "null",
                "protocolVersion": "1.0",
                "service": "null",
                "fwVersion": "null",
                "token": "null",
                "tag": "null",
                "regionInfo": "null",
                "extraDeviceInfo": "null",
                "bindResultInfo": "null",
                "iotId": "null",
                "regIotId": "null",
                "deviceId": "null"
                }
                 */
                LogUtil.i("onDeviceFound: discoveryType=$discoveryType,size=${deviceInfos.size}")

                val list = mutableListOf<Pigeon.DeviceInfo>()
                deviceInfos.forEach {
                    val deviceInfo = Pigeon.DeviceInfo()
                    deviceInfo.linkType = it.linkType
                    deviceInfo.devType = it.devType
                    deviceInfo.productKey = it.productKey
                    deviceInfo.productId = it.productId
                    deviceInfo.mac = it.mac
                    deviceInfo.protocolVersion = it.protocolVersion
                    list.add(deviceInfo)
                }
                flutterApi?.onDeviceFound(discoveryType.type.toLong(), discoveryType.description, list) {}

            }
        });
    }

    override fun stopDiscovery() {
        LocalDeviceMgr.getInstance().stopDiscovery()
    }

    override fun authCodeLogin(authCode: String) {
        initIotSmart()

        val userInfo = LoginBusiness.getUserInfo()
        if (userInfo != null) {
            LogUtil.i("userInfo.openId=${userInfo.openId}")
            LogUtil.i("userInfo.userId=${userInfo.userId}")
            LogUtil.i("userInfo.userPhone=${userInfo.userPhone}")
            LogUtil.i("userInfo.userAvatarUrl=${userInfo.userAvatarUrl}")
            LogUtil.i("userInfo.mobileLocationCode=${userInfo.mobileLocationCode}")
            LogUtil.i("userInfo.userNick=${userInfo.userNick}")
        }
        LogUtil.i("authCodeLogin,authCode=$authCode")

        LoginBusiness.authCodeLogin(authCode, object : ILoginCallback {
            override fun onLoginSuccess() {
                LogUtil.i("authCodeLogin,onLoginSuccess,flutterApi=$flutterApi")
                flutterApi?.onAuthCodeLoginSuccess {
                    LogUtil.i("onAuthCodeLoginSuccess")
                }


            }

            override fun onLoginFailed(i: Int, s: String) {
                LogUtil.i("onLoginFailed code: $i, str: $s")
                flutterApi?.onAuthCodeLoginFailed(i.toLong(), s, {})
            }
        })
    }

    override fun getDeviceToken(deviceName: String, productKey: String, timeout: Long, interval: Long) {

        val param = GetTokenParams()
        param.deviceName = deviceName
        param.productKey = productKey
        param.timeout = timeout.toInt()
        param.interval = interval.toInt()
        LogUtil.i("getDeviceToken getDeviceToken:deviceName=${param.deviceName},productKey=${param.productKey},timeout=$timeout,interval=$interval")

        LocalDeviceMgr.getInstance().getDeviceToken(applicationContext, param, object : IOnTokenGetListerner {
            override fun onSuccess(p0: GetTokenResult?) {
                LogUtil.i("getDeviceToken onSuccess:$p0")
                val flutterGetTOkenResult = Pigeon.GetTokenResult()
                p0?.let {
                    flutterGetTOkenResult.deviceName = it.deviceName
                    flutterGetTOkenResult.productKey = it.productKey
                    flutterGetTOkenResult.token = it.token

                }
                flutterApi?.getDeviceTokenOnSuccess(flutterGetTOkenResult, {})

                // token会变，只能获取一次
                getIotId(flutterGetTOkenResult.token ?: "")

            }

            override fun onFail(p0: DCErrorCode?) {
                LogUtil.i("getDeviceToken onFail:$p0")

                val flutterDcErrorCode = Pigeon.DCErrorCode()
                p0?.let {
                    flutterDcErrorCode.code = it.code
                    flutterDcErrorCode.msg = it.msg
                    flutterDcErrorCode.subcode = it.subcode
                }
                flutterApi?.getDeviceTokenOnFail(flutterDcErrorCode, {})
            }
        })
    }

    override fun toggleProvision(ssid: String, password: String, timeout: Long) {
        LogUtil.i("toggleProvision ssid=$ssid,password=$password,timeout=$timeout")
        AddDeviceBiz.getInstance().toggleProvision(ssid, password, timeout.toInt())
    }


    private fun startDevice() {
        LogUtil.i("startDevice")
        AddDeviceBiz.getInstance().startAddDevice(applicationContext, object : IAddDeviceListener {
            override fun onPreCheck(result: Boolean, dcErrorCode: DCErrorCode?) {
                // 参数检测回调
                LogUtil.i("onPreCheck: result=$result,dcErrorCode=$dcErrorCode")
                val flutterDcErrorCode = Pigeon.DCErrorCode()
                dcErrorCode?.let {
                    flutterDcErrorCode.code = it.code
                    flutterDcErrorCode.subcode = it.subcode
                    flutterDcErrorCode.codeName = it.codeName
                }
                flutterApi?.onPreCheck(if(result) 1 else 0, flutterDcErrorCode, {})
            }

            override fun onProvisionPrepare(prepareType: Int) {
                LogUtil.i("onProvisionPrepare: prepareType=$prepareType,输入账号密码...")
                flutterApi?.onProvisionPrepare(prepareType.toLong(), {})
            }

            override fun onProvisioning() {
                LogUtil.i("onProvisioning 配网中...")
                flutterApi?.onProvisioning({})
            }

            override fun onProvisionStatus(provisionStatus: ProvisionStatus) {
                // 二维码配网会走到这里  provisionStatus=ProvisionStatus.QR_PROVISION_READY表示二维码ready了
                // ProvisionStatus.QR_PROVISION_READY.message() 获取二维码内容
                // 注意：返回二维码时已开启监听设备是否已配网成功的通告，并开始计时，UI端应提示用户尽快扫码；
                // 如果在指定时间配网超时了，重新调用开始配网流程并刷新二维码；
                LogUtil.i("onProvisionStatus,ProvisionStatus=$provisionStatus")
                flutterApi?.onProvisionStatus(provisionStatus.code().toLong(), provisionStatus.message(), {})

            }

            override fun onProvisionedResult(success: Boolean, deviceInfo: DeviceInfo?, dcErrorCode: DCErrorCode?) {
                // 配网结果 如果配网成功之后包含token，请使用配网成功带的token做绑定
                //错误码：https://help.aliyun.com/document_detail/127995.html
                LogUtil.i("onProvisionedResult,success=$success,DeviceInfo=$deviceInfo,DCErrorCode=$dcErrorCode")
                val flutterDcErrorCode = Pigeon.DCErrorCode()
                dcErrorCode?.let {
                    flutterDcErrorCode.code = it.code
                    flutterDcErrorCode.subcode = it.subcode
                    flutterDcErrorCode.codeName = it.codeName
                }

                val flutterDeviceInfo = Pigeon.DeviceInfo()
                deviceInfo?.let {
                    flutterDeviceInfo.productKey = it.productKey
                    flutterDeviceInfo.deviceName = it.deviceName
                    flutterDeviceInfo.productId = it.productId
                    flutterDeviceInfo.token = it.token
                }
                flutterApi?.onProvisionedResult(if(success) 1 else 0, flutterDeviceInfo, flutterDcErrorCode, {})

            }

        })
    }

    fun bindDevice(productKey: String, deviceName: String, token: String) {
        var params = HashMap<String, Any>()
        params["token"] = token
        params["productKey"] = productKey
        params["deviceName"] = deviceName
        LogUtil.i("bindDevice,token=$token,productKey=$productKey")
        // 构建请求
        val request = IoTRequestBuilder()
            .setScheme(com.aliyun.iot.aep.sdk.apiclient.emuns.Scheme.HTTPS) // 设置Scheme方式，取值范围：Scheme.HTTP或Scheme.HTTPS，默认为Scheme.HTTPS
            .setPath("awss/token/user/bind") // 参照API文档，设置API接口描述中的Path，本示例为uc/listBindingByDev
            .setApiVersion("1.0.8")  // 参照API文档，设置API接口的版本号，本示例为1.0.2
            .setAuthType("iotAuth") // 当云端接口需要用户身份鉴权时需要设置该参数，反之则不需要设置
            .setParams(params)
            .build()


        // 获取Client实例，并发送请求
        val ioTAPIClient = IoTAPIClientFactory().getClient();
        ioTAPIClient.send(request, object : IoTCallback {
            override fun onFailure(p0: IoTRequest?, p1: Exception?) {
                LogUtil.i("bindDevice,onFailure:${p1?.toString()}")

            }

            override fun onResponse(p0: IoTRequest?, response: IoTResponse) {
                val code: Int = response.getCode()
                if (200 != code) {
                    //失败示例，参见 "异常数据返回示例"
                    val mesage: String = response.getMessage()
                    val localizedMsg: String = response.getLocalizedMsg()
                    LogUtil.i("bindDevice,onFailure,mesage=${mesage},localizedMsg=$localizedMsg")
                    return
                }
                LogUtil.i("bindDevice,onSuccess")
                getIotId(token)

            }

        })
    }


    override fun getIotId(token: String) {
        var params = HashMap<String, Any>()
        params["token"] = token
        LogUtil.i("getIotId,token=$token")
        // 构建请求
        val request = IoTRequestBuilder()
            .setScheme(com.aliyun.iot.aep.sdk.apiclient.emuns.Scheme.HTTPS) // 设置Scheme方式，取值范围：Scheme.HTTP或Scheme.HTTPS，默认为Scheme.HTTPS
            .setPath("awss/token/check") // 参照API文档，设置API接口描述中的Path，本示例为uc/listBindingByDev
            .setApiVersion("1.0.10")  // 参照API文档，设置API接口的版本号，本示例为1.0.2
            .setAuthType("iotAuth") // 当云端接口需要用户身份鉴权时需要设置该参数，反之则不需要设置
            .setParams(params)
            .build()


        // 获取Client实例，并发送请求
        val ioTAPIClient = IoTAPIClientFactory().getClient();
        ioTAPIClient.send(request, object : IoTCallback {
            override fun onFailure(p0: IoTRequest?, p1: Exception?) {
                LogUtil.i("getIotId,onFailure:${p1?.toString()}")
                handler.post {
                    flutterApi?.onGetIotIdResult(0, p1?.toString() ?: "") {}
                }

            }

            override fun onResponse(p0: IoTRequest?, response: IoTResponse) {
                val code: Int = response.getCode()
                if (200 != code) {
                    //失败示例，参见 "异常数据返回示例"
                    val mesage: String = response.getMessage()
                    val localizedMsg: String = response.getLocalizedMsg()
                    LogUtil.i("getIotId onResponse,onFailure,mesage=${mesage},localizedMsg=$localizedMsg")
                    handler.post {
                        flutterApi?.onGetIotIdResult(0, mesage) {}
                    }
                    return
                }

                val data: String = response.data.toString() ?: ""
                val jsonObject = JSON.parseObject(data)
                val iotId = jsonObject.getString("iotId")
                LogUtil.i("getIotId,onResponse,success,iotId=${iotId}")
                handler.post {
                    flutterApi?.onGetIotIdResult(1, iotId) {}
                }

            }

        })
    }

    //https://help.aliyun.com/document_detail/188280.html
    override fun checkOtaUpgradeInfo(iotId: String, result: Pigeon.Result<Pigeon.OtaNewVersionInfo>?) {

        var params = HashMap<String, Any>()
        params["iotId"] = iotId
        LogUtil.i("checkOtaUpgradeInfo,iotId=$iotId")
        // 构建请求
        val request = IoTRequestBuilder()
            .setScheme(com.aliyun.iot.aep.sdk.apiclient.emuns.Scheme.HTTPS) // 设置Scheme方式，取值范围：Scheme.HTTP或Scheme.HTTPS，默认为Scheme.HTTPS
            .setPath("living/ota/firmware/file/get") // 参照API文档，设置API接口描述中的Path，本示例为uc/listBindingByDev
            .setApiVersion("1.0.0")  // 参照API文档，设置API接口的版本号，本示例为1.0.2
            .setAuthType("iotAuth") // 当云端接口需要用户身份鉴权时需要设置该参数，反之则不需要设置
            .setParams(params)
            .build()


        // 获取Client实例，并发送请求
        val ioTAPIClient = IoTAPIClientFactory().getClient();
        ioTAPIClient.send(request, object : IoTCallback {
            override fun onFailure(p0: IoTRequest?, p1: Exception?) {
                LogUtil.i("checkOtaUpgradeInfo,onFailure:${p1?.toString()}")
                result?.error(Throwable(p1?.toString()))

            }

            override fun onResponse(p0: IoTRequest?, response: IoTResponse) {
                val code: Int = response.getCode()
                if (200 != code) {
                    //失败示例，参见 "异常数据返回示例"
                    val mesage: String = response.getMessage()
                    val localizedMsg: String = response.getLocalizedMsg()
                    LogUtil.i("checkOtaUpgradeInfo onResponse,onFailure,mesage=${mesage},localizedMsg=$localizedMsg")
                    result?.error(Throwable(mesage))
                    return
                }

                val data: String = response.data.toString() ?: ""
                val jsonObject = JSON.parseObject(data)

                val resultData = Pigeon.OtaNewVersionInfo()
                resultData.moduleName = jsonObject.getString("moduleName")
                resultData.currentVersion = jsonObject.getString("currentVersion")
                resultData.status = jsonObject.getString("status")
                resultData.firmwareVersion = jsonObject.getString("firmwareVersion")
                resultData.size = jsonObject.getString("size")
                resultData.sign = jsonObject.getString("sign")
                resultData.signMethod = jsonObject.getString("signMethod")
                resultData.url = jsonObject.getString("url")
                resultData.details = jsonObject.getString("details")
                resultData.otaType = jsonObject.getString("otaType")

                result?.success(resultData)

                LogUtil.i("checkOtaUpgradeInfo,onResponse,success,jsonObject=${jsonObject}")

            }

        })

    }

    data class OtaParam(var iotId: String = "")
    ///https://help.aliyun.com/document_detail/188284.html
    override fun startOta(iotId: String, result: Pigeon.Result<Long>?) {
        val params = HashMap<String, Any>()
        val devices = mutableListOf<HashMap<String, Any>>()
        devices.add(HashMap<String, Any>().apply {
            this.put("iotId",iotId)
        })
        params["devices"] = devices
        LogUtil.i("startOta,iotId=$iotId，devices=$devices")
        // 构建请求
        val request = IoTRequestBuilder()
            .setScheme(com.aliyun.iot.aep.sdk.apiclient.emuns.Scheme.HTTPS) // 设置Scheme方式，取值范围：Scheme.HTTP或Scheme.HTTPS，默认为Scheme.HTTPS
            .setPath("living/ota/confirm") // 参照API文档，设置API接口描述中的Path，本示例为uc/listBindingByDev
            .setApiVersion("1.0.0")  // 参照API文档，设置API接口的版本号，本示例为1.0.2
            .setAuthType("iotAuth") // 当云端接口需要用户身份鉴权时需要设置该参数，反之则不需要设置
            .setParams(params)
            .build()


        // 获取Client实例，并发送请求
        val ioTAPIClient = IoTAPIClientFactory().getClient();
        ioTAPIClient.send(request, object : IoTCallback {
            override fun onFailure(p0: IoTRequest?, p1: Exception?) {
                LogUtil.i("checkOtaUpgradeInfo,onFailure:${p1?.toString()}")
                result?.success(0)
            }

            override fun onResponse(p0: IoTRequest?, response: IoTResponse) {
                val code: Int = response.getCode()
                if (200 != code) {
                    //失败示例，参见 "异常数据返回示例"
                    val message: String = response.getMessage()
                    val localizedMsg: String = response.getLocalizedMsg()
                    LogUtil.i("checkOtaUpgradeInfo onResponse,onFailure,mesage=${message},localizedMsg=$localizedMsg")
                    result?.success(0)
                    return
                }
                result?.success(1)
                LogUtil.i("checkOtaUpgradeInfo,onResponse,success")
            }
        })
    }

    override fun getOtaProgress(iotId: String, result: Pigeon.Result<Pigeon.OtaUpgradeProgress>?) {

        var params = HashMap<String, Any>()
        params["iotId"] = iotId
        LogUtil.i("getOtaProgress,iotId=$iotId")
        // 构建请求
        val request = IoTRequestBuilder()
            .setScheme(com.aliyun.iot.aep.sdk.apiclient.emuns.Scheme.HTTPS) // 设置Scheme方式，取值范围：Scheme.HTTP或Scheme.HTTPS，默认为Scheme.HTTPS
            .setPath("living/ota/progress/get") // 参照API文档，设置API接口描述中的Path，本示例为uc/listBindingByDev
            .setApiVersion("1.0.0")  // 参照API文档，设置API接口的版本号，本示例为1.0.2
            .setAuthType("iotAuth") // 当云端接口需要用户身份鉴权时需要设置该参数，反之则不需要设置
            .setParams(params)
            .build()


        // 获取Client实例，并发送请求
        val ioTAPIClient = IoTAPIClientFactory().getClient();
        ioTAPIClient.send(request, object : IoTCallback {
            override fun onFailure(p0: IoTRequest?, p1: Exception?) {
                LogUtil.i("checkOtaUpgradeInfo,onFailure:${p1?.toString()}")
                result?.error(Throwable(p1?.toString()))

            }

            override fun onResponse(p0: IoTRequest?, response: IoTResponse) {
                val code: Int = response.getCode()
                if (200 != code) {
                    //失败示例，参见 "异常数据返回示例"
                    val mesage: String = response.getMessage()
                    val localizedMsg: String = response.getLocalizedMsg()
                    LogUtil.i("checkOtaUpgradeInfo onResponse,onFailure,mesage=${mesage},localizedMsg=$localizedMsg")
                    result?.error(Throwable(mesage))
                    return
                }

                val data: String = response.data.toString()
                val jsonObject = JSON.parseObject(data)

                val resultData = Pigeon.OtaUpgradeProgress()
                resultData.iotId = jsonObject.getString("iotId")
                resultData.moduleName = jsonObject.getString("moduleName")
                resultData.currentVersion = jsonObject.getString("currentVersion")
                resultData.status = jsonObject.getString("status")
                resultData.firmwareVersion = jsonObject.getString("firmwareVersion")
                resultData.details = jsonObject.getString("details")
                resultData.otaType = jsonObject.getString("otaType")
                resultData.desc = jsonObject.getString("desc")
                resultData.step = jsonObject.getInteger("step").toLong()
                resultData.needConfirm = if(jsonObject.getBoolean("needConfirm")) 1 else 0

                result?.success(resultData)

                LogUtil.i("checkOtaUpgradeInfo,onResponse,success,jsonObject=${jsonObject}")

            }

        })
    }

}
